package user.main;

import fileparsing.ReadObservations;
import fileparsing.ReadProbabilities;
import filewriting.*;
import guiobjects.Observation;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;

import commonfunctions.Functions;
import commonfunctions.Matrix;
import datacreation.*;


/**
 * This class is for debugging. Runs most of the programs in the system, creating a new group of
 * observations, tracking them, then displaying the results.
 * 
 * @author Trevor Terris
 *
 */
public class RunAll
{
	public static void main (String[] args)
	{
		try 
		{
			System.out.println("Runs through the entire system.");
			System.out.println();
	
	    	System.out.println("What directory should be created for data?");
	    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    	String dirName = br.readLine();
	    	
	    	System.out.println("Creating raw observations.");
			//creates the group of observations
	    	ArrayList<Observation> obs;
	    	if (dirName.compareTo("test") != 0)
	    		obs = ObservationCreator.createData(dirName);
	    	else
	    		obs = ReadObservations.listOfObservations(dirName);

	    	System.out.println("Calculating weights.");
	    	Matrix weights;
	    	if (dirName.compareTo("test") != 0)
	    		weights = WeightsCreator.createData(obs, dirName);
	    	else
	    		weights = ReadProbabilities.probabilityMatrix(dirName);

	    	System.out.println("Finding tracks.");
			Matrix tracks = TracksCreator.createData(obs, weights, dirName);
			
			System.out.println("Total score: " + Functions.getPathSums(weights, tracks));
			
			TrackerThread threads = new TrackerThread();

			threads.addThread(ObservationsWriter.startWriting(obs, dirName), 
					"Done writing observations to file.");
			
			threads.addThread(ProbabilityMatrixWriter.startWriting(weights, dirName), 
					"Done writing weights to file.");
			
			threads.addThread(PruneGraphWriter.startWriting(tracks, dirName), 
					"Done writing tracks to file.");
			
			threads.addThread(SimpleViewWriter.startWriting(obs, weights, tracks, dirName), 
					"Done writing simplified graphical output.");

			threads.addThread(PathDisplayWriter.startWriting(obs, weights, tracks, dirName), 
					"Done writing graphical tracked output.");
			
			threads.addThread(FitnessViewWriter.startWriting(obs, weights, tracks, dirName), 
					"Done writing visualization of path fitness.");
			
			threads.start();
		}
		catch (Exception e)
		{
			e.printStackTrace();
			System.out.println("IO exception.");
		}
	}
}
